package com.dd.dg.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 描述: 路由配置
 *
 * @author: yanglin
 * @Date: 2021-03-08-15:15
 * @Version: 1.0
 */
@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        RouteLocator routeLocator =  builder.routes()
                // 登录页面
                .route("dd-login-01", r -> r.path("/login")
                        .uri("lb://dd-auth"))
                // 注销
                .route("dd-logout-01", r -> r.path("/logout")
                        .uri("lb://dd-auth"))
                // 登录接口
                .route("dd-login-02", r -> r.path("/access/auth/login")
                        .uri("lb://dd-auth"))
                // 登录页面静态资源
                .route("dd-login-03", r -> r.path("/js/**")
                        .uri("lb://dd-auth"))
                .route("dd-login-04", r -> r.path("/css/**")
                        .uri("lb://dd-auth"))
                .route("dd-login-05", r -> r.path("/img/**")
                        .uri("lb://dd-auth"))
                // 主页
                .route("dd-index-01", r -> r.path("/index")
                        .uri("lb://dd-user-ui"))
                // 主页页面静态资源
                .route("dd-index-02", r -> r.path("/static/**")
                        .uri("lb://dd-user-ui"))
                .route("dd-index-03", r -> r.path("/layui/**")
                        .uri("lb://dd-user-ui"))
                .route("dd-index-04", r -> r.path("/common/**")
                        .uri("lb://dd-user-ui"))
                // 用户管理
                .route("dd-user-01", r -> r.path("/user*")
                        .uri("lb://dd-user-ui"))
                .route("dd-user-03", r -> r.path("/user/c/**")
                        .uri("lb://dd-user-ui"))
                // 角色管理
                .route("dd-role-01", r -> r.path("/role*")
                        .uri("lb://dd-user-ui"))
                .route("dd-role-02", r -> r.path("/role/c/**")
                        .uri("lb://dd-user-ui"))
                // 菜单管理
                .route("dd-menu-01", r -> r.path("/permission*")
                        .uri("lb://dd-user-ui"))
                .route("dd-menu-02", r -> r.path("/permission/c/**")
                        .uri("lb://dd-user-ui"))
                // 数据字典
                .route("dd-code-01", r -> r.path("/code*")
                        .uri("lb://dd-user-ui"))
                .route("dd-code-02", r -> r.path("/code/c/**")
                        .uri("lb://dd-user-ui"))
                // 用户等级
                .route("dd-level-01", r -> r.path("/level*")
                        .uri("lb://dd-user-ui"))
                .route("dd-level-02", r -> r.path("/level/c/**")
                        .uri("lb://dd-user-ui"))
                .build();
        return routeLocator;
    }
}
